package com.carkeeper.car.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carkeeper.car.Itcast;
import com.carkeeper.car.mapper.ItcastMapper;
import com.carkeeper.car.service.ItcastService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;

@Service
public class ItcastServiceImpl implements ItcastService {

    @Autowired
    private ItcastMapper itcastMapper;

    @Override
    public Itcast findById(Long id) {
        return itcastMapper.selectById(id);
    }

    @Override
    public Page<Itcast> findPage(Itcast itcast, Long pageNo, Long pageSize) {
        QueryWrapper<Itcast> queryWrapper = new QueryWrapper<>();

        if (itcast != null) {
            if (StringUtils.isNotBlank(itcast.getName())) {
                queryWrapper.like("name", itcast.getName());
            }
        }
        //设置分页
        Page<Itcast> pagination = new Page<>(pageNo, pageSize);
        return itcastMapper.selectPage(pagination, queryWrapper);
    }

    @Override
    public Integer insert(Itcast itcast) {
        return itcastMapper.insert(itcast);
    }

    @Override
    public Integer updateById(Itcast itcast) {
        return itcastMapper.updateById(itcast);
    }

    @Override
    public Integer delete(Long id) {
        return itcastMapper.deleteById(id);
    }

    @Override
    public Integer deleteAll(Long[] ids) {
        return itcastMapper.deleteBatchIds(Arrays.asList(ids));
    }
}
